import os
import sys
from pathlib import Path

import django

root_path = Path(__file__).absolute().parent.parent.parent.as_posix()
sys.path.insert(0, root_path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.settings")

django.setup()

from apps.products.models import Category  # noqa: E402


def init_categories():
    categories = [
        "皮带输送系统",
        "齿形同步线输送系统",
        "爬坡输送系统",
        "倍速链输送系统",
        "滚筒输送系统",
        "链条工装治具输送系统",
        "柔性输送系统",
        "配件"
    ]

    for category_name in categories:
        category, created = Category.objects.get_or_create(
            name=category_name,
            defaults={
                'title': category_name,
                'description': category_name,
            }
        )
        if created:
            print(f"Created category: {category.name}")
        else:
            print(f"Category already exists: {category.name}")

    print("Categories created successfully!")


if __name__ == '__main__':
    init_categories()
